<?php
class My_Helper_View_StringTrim extends Zend_View_Helper_Abstract
{
    public function stringTrim($content,$length)
    {

        if(strlen($content)<=$length)
        {
            return $content;
        }else{
            if(preg_match('/(.{' . $length. '}.*?)\s/', $content, $matches)||
                    preg_match('/(.{' . $length. '}.*?)\Z/', $content, $matches2) )
            {
                if(!empty($matches2[1]))
                {
                    return rtrim($matches2[1]);
                }
                elseif($matches[1]!='')
                    return rtrim($matches[1]).'...' ;

            }else{
                $content = mb_substr($content,0,$length,'utf-8');
            }
        }
        return $content. ' ...';
    }
}